package clientgo

import (
    "k8s.io/client-go/rest"
)

type K8sConfig struct {
    Name  string // 集群名称
    Host  string // 集群地址
    Token string // Token
}

type Controller struct{
    Clients map[string]*rest.Config
}

var (
	// TODO: 从数据库获取集群信息并初始化，以及新增集群信息后刷新客户端
    allConfig = []K8sConfig{
        {
            Name:  "test",
            Host:  "https://192.168.21.120:6443",
            Token: "eyJhbGciOiJSUzI1NiIsImtpZCI6InM3bFg0Ujc5OHhmQ1lYMFBQMHZtckM5V1JuU2hNRzdfU1p4MlJWYlFNVDQifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlc3BoZXJlLWNvbnRyb2xzLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJrdWJlc3BoZXJlLWNsdXN0ZXItYWRtaW4tdG9rZW4tbmtycGciLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoia3ViZXNwaGVyZS1jbHVzdGVyLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiNTdiYjhkZTgtM2M0Zi00NzE0LWEyMzEtMmI1YWUzYWE1NTRhIiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmVzcGhlcmUtY29udHJvbHMtc3lzdGVtOmt1YmVzcGhlcmUtY2x1c3Rlci1hZG1pbiJ9.NcqtKQOfnHPcHCc0ElpjRblh65I3TXrVueIZyuDKhXZ0f3nJxM38-HBS-BVy935yOu0OT9Bc4YoodHhE-lKujJCELoHeKFbc7hixtMJpYMonFvV1okd3wReHd2C9PKhbItbAwz6nK7hmaCq3MX4HeQYDo_U90_uezo-kVCIry8EOR5O5xKX4JwZN1D7NaQXIL59mcwbeBYouwE3D5hftV6rW-sanY8IvAgj34cGPtVJmm4xY-68yW8gj9YJG4h2BFoQmLVNgU8ehsuJRsAeZuRj7WcUAoVEcdUGhBUdwTe-2TTF23sJ8RgPybdospbctOJTNs2Bw3XsMqLA3GcgN_g", // 存放 serviceaccount对应secret的token
        },
    }
    // 可继续添加其他集群配置
)

// 初始化客户端，并存入变量供后续使用
func (c *Controller) NewClustersConfig() {
	// 存放所有客户端的配置
	var Clients = make(map[string]*rest.Config, 0)
    for _, env := range allConfig {
        Clients[env.Name] = &rest.Config{
            Host:            env.Host,
            BearerToken:     env.Token,
            BearerTokenFile: "",
            TLSClientConfig: rest.TLSClientConfig{
                Insecure: true,  // 设置为true时 不需要CA
            },
        }
    }
    c.Clients = Clients
}